﻿$filePath = "D:\Docs\数据同步\对接表数据汇总_ordered.txt";
$content = Get-Content $filePath;
$lst = $content;
#$lst | Sort-Object {$_.Split()[1]} >> f:\test.txt

#测量行数
#Get-Content "f:\test.txt" | %{$_.Split()[0]}  | measure -Sum

#format output
$format = "insert into hvr_action (CHN_NAME, GRP_NAME, TBL_NAME, ACT_NAME, ACT_PARAMETERS) values ('yy', 'SRC', '{0}', 'ColumnProperties', '/Name={1} /CaptureExpression=`"''510010''||{{{1}}}`"');";
$output = "";
foreach ($line in $lst)
{
   $items = $line.Split("	",[StringSplitOptions]::RemoveEmptyEntries);
   if ($items.Length -lt 3)
   {
       #continute;
       continue;
   }
   $flag = $items[0];
    $tableName = $items[1].ToLower();
   $fieldNames = $items[2].Split(",",[StringSplitOptions]::RemoveEmptyEntries);
   if ($fieldNames.Length -gt 1)
   {
       foreach ($fieldName in $fieldNames)
       {
          # $str =  "{0,-5} {1,-40} {2,-30}" -f  $flag,$tableName,$fieldName;
           $str =  $format -F $tableName,($fieldName.ToLower());
           $output +=  $str +[System.Environment]::NewLine;
       }
   }
   else
   {
     $fieldName = $fieldNames[0];
     #$str =  "{0,-5} {1,-40} {2,-30}" -f  $flag,$tableName,$fieldName;
     $str =  $format -F $tableName,($fieldName.ToLower());
     $output +=  $str +[System.Environment]::NewLine;
   }
}

$output >> "f:/ttt.txt"
	#dir | ForEach-Object { "{0,-20} = {1,10} Bytes" -f $_.name, $_.Length } >> "f:ttt.txt"